package com.zyj.test.month1.day2;

/**
 * @author Yijia Zhang
 * @create 2024-04-23 22:32
 */
public class code1052 {
    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        //total表示最基本的满意客户数量
        int total = 0;

        //maxProfit表示能增加的满意客户数量
        int maxProfit = 0;
        for (int i = 0; i < minutes; i++) {
            if (grumpy[i] == 1) {
                maxProfit += customers[i];
            } else {
                total += customers[i];
            }
        }
        int r = minutes;
        int now = maxProfit;
        while (r < customers.length) {
            if (grumpy[r] == 0) {
                total += customers[r];
            }
            now += customers[r] * grumpy[r];
            now -= grumpy[r - minutes] * customers[r - minutes];
            maxProfit = Math.max(maxProfit, now);
            r++;
        }
        return total + maxProfit;
    }
}
